﻿@using Masuit.MyBlogs.Core.Models.DTO
@using Masuit.MyBlogs.Core.Models.Entity
@using Masuit.MyBlogs.Core.Models.ViewModel
@using Masuit.Tools.Core.Net
@using Masuit.MyBlogs.Core.Common
@using Masuit.MyBlogs.Core.Infrastructure.Services.Interface
@using Masuit.MyBlogs.Core.Models.Enum
@using EFCoreSecondLevelCacheInterceptor
@model Masuit.MyBlogs.Core.Models.ViewModel.HomePageViewModel
@inject ICategoryService CategoryService
@{
	Category cat = ViewBag.Category;
	ViewBag.Title = "分类_" + cat.Name;
	Layout = "~/Views/Shared/_Layout.cshtml";
	Random r = new Random();
	var alllist = CategoryService.GetQuery(c => c.Status == Status.Available && c.ParentId == null&&c.Post.Count>0, c => c.Name).Select(c => new{c.Id,c.Name}).Cacheable().ToList();
	var children = cat.ParentId==null?cat.Children:cat.Parent.Children.Where(c => c.Status == Status.Available && c.Post.Count>0).OrderBy(c => c.Id).ToList();
}
<style>
	.bg-title {
		height: 50vh;
		max-height: 400px;
		position: relative;
		background: url(/Content/images/@(r.Next(1,9)).jpg) no-repeat center;
		background-size:cover;
		background-attachment: fixed;
		margin-bottom: 10px;
	}
	.header-content {
		position: absolute;
		left: 50%;
		top: 50%;
		transform: translate(-50%,-50%);
	}
	.header-content .divider {
		width: inherit;
		height: 20px;
		margin-top: 20px;
		border-top: 3px solid rebeccapurple;
	}
</style>
<div class="container">
	<ol class="cd-breadcrumb triangle">
		<li><a asp-controller="Home" asp-action="Index">首页</a></li>
		<li><a asp-controller="Home" asp-action="Post">文章列表</a></li>
		@if(cat.ParentId>0) {
			<li><a asp-controller="Home" asp-action="Category" asp-route-id="@cat.ParentId">@cat.Parent.Name</a></li>
		}
		<li class="current"><em>@cat.Name</em></li>
	</ol>
</div>
<div class="bg-title">
	<div class="header-content text-center">
		<h1 class="size48">
			@if(cat.ParentId>0) {
			    @(cat.Parent.Name+" / ")
			}
			@cat.Name
			@if(CommonHelper.SystemSettings.GetOrAdd("EnableRss", "true") == "true"){
				<a class="btn btn-lg btn-success" asp-controller="Subscribe" asp-action="CategoryRss" asp-route-id="@cat.Id" target="_blank">
					<i class="icon-rss4"></i>
				</a>
			}
			<a class="btn btn-lg btn-danger" onclick='blockCategory("@cat.Id","@cat.Name")'>
				<i class="icon-blocked"></i>
			</a>
		</h1>
		<div class="divider"></div>
		<p class="size24">
			@cat.Description
		</p>
	</div>
</div>
<div class="container">
	<p>
		一级分类：
		@foreach (var category in alllist)
		{
			if (cat.Id==category.Id||cat.ParentId==category.Id) {
				<a class="text-red" asp-controller="Home" asp-action="Category" asp-route-id="@category.Id">@category.Name</a><text> | </text>
			} else {
				<a asp-controller="Home" asp-action="Category" asp-route-id="@category.Id">@category.Name</a><text> | </text>
			}
		}
	</p>
	@if(children.Count>0) {
		<hr />
		<p>
			<text>二级分类：</text>
			@foreach (var category in children)
			{
				if (cat.Id==category.Id) {
					<a class="text-red" asp-controller="Home" asp-action="Category" asp-route-id="@category.Id">@category.Name</a><text> | </text>
				} else {
					<a asp-controller="Home" asp-action="Category" asp-route-id="@category.Id">@category.Name</a><text> | </text>
				}
			}
		</p>
	}
	<hr />
</div>
@{
	var user = Context.Session.Get<UserInfoDto>(SessionKey.UserInfo) ?? new UserInfoDto();
	await Html.RenderPartialAsync(user.IsAdmin ? "_MainContainer_Admin" : "_MainContainer", Model);
}